/**
 * @author Pawel Gadecki <pidzama@gmail.com>
 */
package spwodne;

import java.util.Date;
import java.util.List;
import javax.swing.table.AbstractTableModel;

public class MTWplaty extends AbstractTableModel {

    MTWplaty(Klient k) {
        klient = k;
        l = klient.getLWpl();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public int getRowCount() {
        return l.size();
    }

    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }

    @Override
    public Object getValueAt(int row, int col) {
        Object tmp;
        switch (col) {
            case 0: // '\0'

                tmp = ((Wplata) l.get(row)).getKwota();
                break;

            case 1: // '\001'

                tmp = ((Wplata) l.get(row)).getDate();
                break;

            default:
                System.out.println("getValue out of bounds");
                tmp = null;
                break;
        }
        return tmp;
    }

    @Override
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    public void addRow(float kwota, Date data) {
        klient.wplac(Float.valueOf(kwota), data);
        fireTableDataChanged();
    }

    public void delRow(int n) {
        klient.usunWplate(n);
        fireTableDataChanged();
    }
    private List l;
    private Klient klient;
    private String columnNames[] = {
        "Kwota [z\u0142]", "Data"
    };
}
